<template>
  <div>
    <!-- 背景图和头像 -->
    <div class="my-title">
      <!-- 背景图 -->
      <div class="my-title-img">
        <img src="http://liufusong.top:8080/img/profile/bg.png" alt />
      </div>
      <!-- 头像 -->
      <div class="my-info">
        <div class="my-info-mian">
          <div class="info-tx">
            <img src="http://liufusong.top:8080/img/profile/avatar.png" alt />
          </div>
          <div class="info-wz">
            <p>游客</p>
          </div>
          <div class="info-login" @click="myLogin" v-if="isShow">
            <span>去登录</span>
          </div>
          <div class="tuichu" v-if="!isShow" @click="tuiChu">  

            <span>退出</span>
            <p>编辑个人资料 ></p>
          </div>
        </div>
      </div>
      <!-- vant 图片和文字 -->
      <div>
        <van-grid :border="false" :column-num="3"></van-grid>
      </div>
    </div>
    <!-- 宫格内容 -->
    <div class="gongge">
      <van-grid :column-num="3" :border="false">
        <van-grid-item
          v-for="value in list"
          :key="value.icon"
          :icon="value.icon"
          :text="value.text"
        />
      </van-grid>
    </div>
    <!-- 加入我们 -->
    <div class="my-jrwm">
      <img :src="srcImg" alt />
    </div>
  </div>
</template>

<script>
import { userInfo } from '@/api/user';
import { getItem, key, removeItem } from '@/store/index';
// import { Toast } from 'vant';
export default {
  name: 'UserPage',
  data() {
    return {
      srcImg: 'http://liufusong.top:8080/img/profile/join.png',
      list: [
        { icon: 'star-o', text: '我的收藏' },
        { icon: 'home-o', text: '我的出租' },
        { icon: 'clock-o', text: '看房记录' },
        { icon: 'credit-pay', text: '成为房主' },
        { icon: 'contact', text: '个人资料' },
        { icon: 'service-o', text: '联系我们' },
      ],
      isShow: true,
    };
  },
  created() {
    if (getItem(key) !== null) {
      this.isShow = false;
    } else if (getItem(key) == null) {
      this.isShow = true;
    }
    this.uInfo();
  },
  methods: {
    myLogin() {
      this.$router.push('/login');
    },
    async uInfo() {
      const res = await userInfo(getItem(key));
      console.log(res);
    },
    tuiChu() {
      removeItem(key);
      console.log(111);
      this.isShow = true;
      this.$router.push('/login');
    },
  },
};
</script>
<style lang="less">
//背景图和头像
.my-title {
  position: relative;
  .my-title-img {
    width: 100%;
    height: 191px;
    // background-color: pink;
    img {
      width: 100%;
    }
  }
  //头像
  .my-info {
    position: absolute;
    bottom: -108px;
    left: 50%;
    transform: translateX(-50%);
    .my-info-mian {
      font-size: 13px;
      display: flex;
      align-items: center;
      flex-direction: column;
      width: 319px;
      height: 165px;
      box-shadow: 0 0 15px 0 rgba(0, 0, 0, 0.35);
      background-color: #fff;
      position: relative;
      .info-tx {
        position: absolute;
        top: -30px;
        left: 125px;
        width: 70px;
        height: 70px;
        box-shadow: 0 0 15px 0 rgba(0, 0, 0, 0.35);
        background-color: #fff;
        border-radius: 50%;
        img {
          padding-top: 5px;
          width: 60px;
          height: 60px;
          display: block;
          margin: 0 auto;
        }
      }
      .info-wz {
        margin-top: 45px;
      }
      .info-login {
        height: 25px;
        width: 60px;
        line-height: 25px;
        text-align: center;
        border-radius: 8%;
        background-color: #21b97a;
        color: #fff;
      }
      .tuichu {
        height: 35px;
        width: 60px;
        line-height: 35px;
        text-align: center;
        border-radius: 8%;
        background-color: #21b97a;
        color: #fff;
        position: relative;
        h4{
          width: 100px;
          height: 30px;
          color: rgb(110, 109, 109);
        }
        p {
          position: absolute;
          top: 23px;
          left: -15px;
          width: 100px;
          height: 30px;
          color: rgb(110, 109, 109);
        }
      }
    }
  }
}
.gongge {
  margin-top: 125px;
}
.my-jrwm {
  width: 375px;
  height: 93px;
  img {
    text-align: center;
    margin: 10px 10px 10px 15px;
    width: 345px;
    height: 85px;
  }
}
</style>
